package cn.wizzer.app.web.modules.controllers.user;

import cn.wizzer.app.user.modules.models.enums.GoodsCategoryEnum;
import cn.wizzer.app.user.modules.services.GoodsService;
import cn.wizzer.app.web.commons.filter.ApiTokenFilter;
import cn.wizzer.framework.base.Result;
import cn.wizzer.framework.filter.ParamFilter;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;


@Api(value = "/api/user/mall", tags = "钻石商城")
@IocBean
@At("/api/user/mall")
public class ApiUserMallController {
    @Inject
    @Reference
    private GoodsService goodsService;


    /**
     * 商品列表(分页)。根据id查询商品详情
     *
     * @param goodsCategory String 分类id
     * @param pageNumber    int
     * @param pageSize      int
     * @return Object
     */
    @At
    @Ok("json:full")
    @Filters({@By(type = ApiTokenFilter.class), @By(type = ParamFilter.class)})
    public Object goodsList(@Param("id") String id, @Param("goodsCategory") String goodsCategory, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize) {
        return Result.success().addData(goodsService.listPage(pageNumber, pageSize, null, id, goodsCategory));
    }

    /**
     * 查询所有分类
     *
     * @return Object
     */
    @At("/categoryList")
    @Ok("json")
    @Filters({@By(type = ApiTokenFilter.class), @By(type = ParamFilter.class)})
    public Object categoryList() {
        return Result.success().addData(GoodsCategoryEnum.toList());
    }

    /**
     * 查询商品信息
     *
     * @param id
     * @return
     */
    @At
    @Ok("json")
    @Filters({@By(type = ApiTokenFilter.class), @By(type = ParamFilter.class)})
    public Object goodsInfo(@Param("id") String id) {
        return Result.success().addData(goodsService.fetch(id));
    }

}